While they are extraordinarily useful, pointers are not the most intuitive concept in the world. Pointers to pointers are even harder to understand
and use correctly. And with each additional level of indirection, pointer variables become more difficult to use correctly. Therefore pointer
declarators should be limited to no more than two levels of nesting.
Noncompliant code example
typedef int * INTPTR;
struct s {
int ** s1;
int *** s2; // Noncompliant
};
struct s ** ps1;
struct s *** ps2; // Noncompliant
int ** ( *pfunc1)();
int ** ( **pfunc2)();
int ** (***pfunc3)(); // Noncompliant
int *** ( **pfunc4)(); // Noncompliant
void function( int ** par1,
int *** par2, // Noncompliant
INTPTR * par3,
int * par4[],
int ** par5[]) // Noncompliant
{
int ** ptr1;
int *** ptr2; // Noncompliant
INTPTR * ptr3;
int * ptr4[ 10 ];
int ** ptr5[ 10 ]; //Noncompliant
}
Compliant solution
typedef int * INTPTR;
struct s {
int ** s1;
int ** s2;
};
struct s ** ps1;
struct s ** ps2;
int ** (*pfunc1)();
int ** (**pfunc2)();
int ** (**pfunc3)();
int ** (**pfunc4)();
void function( int ** par1,
int ** par2,
INTPTR * par3,
int * par4[],
int * par5[])
{
int ** ptr1;
int ** ptr2;
INTPTR * ptr3;
int * ptr4[ 10 ];
int * ptr5[ 10 ];
}